﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace LightManager.UserControls.UnitEditor
{
    public partial class UnitEditorForm : Form
    {
        public UnitEditorForm()
        {
            InitializeComponent();
        }

        public Unit CreateUnit(string name)
        {
            this.unitEditorControl.Unit = new Unit() { IsEnemy = true, Name = name };
            this.btnComplete.Text = "Inserisci in gioco";
            DialogResult response = this.ShowDialog();
            if (response != DialogResult.OK) return null;
            return this.unitEditorControl.ApplyChanges();
        }

        public void EditUnit(Unit unit)
        {
            this.unitEditorControl.Unit = unit;
            this.btnComplete.Text = "Salva e prosegui";
            DialogResult response = this.ShowDialog();
            if (response != DialogResult.OK) return;
            unit = this.unitEditorControl.ApplyChanges();
        }

        public event EventHandler<ValidationEventArgs> NameValidation
        {
            add { this.unitEditorControl.NameValidation += value; }
            remove { this.unitEditorControl.NameValidation -= value; }
        }

        public Unit Unit
        {
            get { return this.unitEditorControl.Unit; }
        }

        private void UnitEditorForm_FormClosing(object sender, FormClosingEventArgs e)
        {
            if (this.DialogResult == System.Windows.Forms.DialogResult.OK)
                e.Cancel = this.unitEditorControl.HaveErrors;
        }
    }
}
